package cn.tedu.truetaste.controller;

import cn.tedu.truetaste.pojo.dto.TableAddNewDTO;
import cn.tedu.truetaste.pojo.dto.TableUpdateDTO;
import cn.tedu.truetaste.pojo.vo.TableListItemVO;
import cn.tedu.truetaste.pojo.vo.TableStandardVO;
import cn.tedu.truetaste.service.ITableService;
import cn.tedu.truetaste.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("tables")
@Api(tags = "餐桌管理模块")
public class TableController {
    @Autowired
    private ITableService tableService;

    public TableController() {
        log.info("创建控制器对象：TableController");
    }

    // http://localhost:9989/tables/add-new
    @ApiOperation("添加餐桌")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(TableAddNewDTO tableAddNewDTO) {
        log.debug("开始处理【添加店铺】的请求，参数：{}", tableAddNewDTO);
        tableService.addNew(tableAddNewDTO);
        return JsonResult.ok();
    }
    // http://localhost:9989/tables/delete
    @ApiOperation("删除餐桌")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "餐桌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除餐桌】的请求，参数：{}", id);
        tableService.delete(id);
        return JsonResult.ok();
    }


    // http://localhost:9989/tables/update
    @ApiOperation("修改餐桌详情")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "餐桌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> updateById(@PathVariable Long id, TableUpdateDTO tableUpdateDTO) {
        log.debug("开始处理【修改餐桌详情】的请求，参数ID：{}, 新数据：{}", id, tableUpdateDTO);
        tableService.updateInfoById(id, tableUpdateDTO);
        return JsonResult.ok();
    }


    @ApiOperation("根据id查询餐桌详情")
    @ApiOperationSupport(order = 400)
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<TableStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询餐桌详情】的请求，参数：{}", id);
        TableStandardVO table = tableService.getStandardById(id);
        return JsonResult.ok(table);
    }
    // http://localhost:9989/tables/
    @ApiOperation("查询餐桌列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult<List<TableListItemVO>> list() {
        log.debug("开始处理【查询餐桌列表】的请求，无参数");
        List<TableListItemVO> list = tableService.list();
        return JsonResult.ok(list);
    }
}
